<?php

namespace Modules\Common\Services;

use Modules\Common\CodeData;
use Modules\Common\StatusData;
use \Illuminate\Http\JsonResponse;

class BaseService
{

    /***
     * @param array $data
     * @param string $msg
     * @param int $status
     * @param int $code
     * @return JsonResponse
     */
    public function buildSuccess(array $data = [],string $msg = '操作成功', int $status = StatusData::SUCCESS,int $code = CodeData::OK):JsonResponse
    {
        return response()->json([
            'status'  => $status,
            'message' => $msg,
            'data'    => $data
            ],$code);
    }

    /***
     * @param int $status
     * @param int $code
     * @param string $msg
     * @param array $data
     * @return JsonResponse
     */
    public function buildFailed(int $status,string $msg = '操作失败',int $code = CodeData::OK ,array $data = []):JsonResponse
    {
        return response()->json([
            'status'  => $status,
            'message' => $msg,
            'data'    => $data
        ],$code);
    }


}
